#!/bin/bash

CheckProcess(){

if [ "$1" = "" ];
then
	return 1
fi

PROCESS_NUM=`ps -ef | grep "$1" | grep -v "grep" | wc -l` 
if [ $PROCESS_NUM -eq 1 ];
then
	return 1
else
	return 0
fi
}

main(){
#------------------------------------------------------------------------------------------------------------
CheckProcess "ossImsAlarm.jar"
Check_RET=$?
if [ $Check_RET -eq 0 ];
then
	echo "lostossImsAlarm.jar"
	sed -i '/10.239.50.33/d' /root/.ssh/known_hosts
	ALARMSH_PORT=`ps -ef |grep ossImsAlarm.sh |grep -w 'ossImsAlarm.sh'|grep -v 'grep'|awk '{print $2}'`
	kill -9 $ALARMSH_PORT
	SSHOSS_PORT=`ps -ef |grep alarmintegration |grep -w 'alarmintegration'|grep -v 'grep'|awk '{print $2}'`
	kill -9 $SSHOSS_PORT
	nohup java -jar /opt/Ericsson/core/bin/ossImsAlarm.jar >/dev/null 2>&1 &
	sleep 10
else
	echo "ok"
fi
#-------------------------------------------------------------------------------------------------------------
CheckProcess "ossImsAlarm.sh"
Check_RET=$?
if [ $Check_RET -eq 0 ];
then
	echo "lostossImsAlarm.sh"
	sed -i '/10.239.50.33/d' /root/.ssh/known_hosts
	ALARMJAR_PORT=`ps -ef |grep ossImsAlarm.jar |grep -w 'ossImsAlarm.jar'|grep -v 'grep'|awk '{print $2}'`
	kill -9 $ALARMJAR_PORT
	SSHOSS_PORT=`ps -ef |grep alarmintegration |grep -w 'alarmintegration'|grep -v 'grep'|awk '{print $2}'`
	kill -9 $SSHOSS_PORT
	nohup java -jar /opt/Ericsson/core/bin/ossImsAlarm.jar >/dev/null 2>&1 &
	sleep 10
else
	echo "ok"
fi
#-------------------------------------------------------------------------------------------------------------
CheckProcess "alarmintegration"
Check_RET=$?
if [ $Check_RET -eq 0 ];
then
	echo "lostalarmintegration"
	sed -i '/10.239.50.33/d' /root/.ssh/known_hosts
	ALARMJAR_PORT=`ps -ef |grep ossImsAlarm.jar |grep -w 'ossImsAlarm.jar'|grep -v 'grep'|awk '{print $2}'`
	kill -9 $ALARMJAR_PORT
	ALARMSH_PORT=`ps -ef |grep ossImsAlarm.sh |grep -w 'ossImsAlarm.sh'|grep -v 'grep'|awk '{print $2}'`
	kill -9 $ALARMSH_PORT
	nohup java -jar /opt/Ericsson/core/bin/ossImsAlarm.jar >/dev/null 2>&1 &
	sleep 10
else
	echo "ok"
fi
}
main
